/**
 * Booleans and boolean logic
 * 
 * We can encode booleans and boolean logic using combinators.
 */

import { I, M, K, KI, C } from './combinators/combinators1.mjs';

const True = K;
const False = KI;

Function.prototype.toJsBool = function() {
  return this(true)(false);
};

const not = C;
console.log("Not");
console.log(not(True).toJsBool());
console.log(not(False).toJsBool());

const or = M;
console.log("Or");
console.log(or(True)(True).toJsBool());
console.log(or(False)(True).toJsBool());
console.log(or(True)(False).toJsBool());
console.log(or(False)(False).toJsBool());

const ifThenElse = I;
console.log("IfThenElse");
console.log(ifThenElse(True)('It was true')('It was false'));
console.log(ifThenElse(False)('It was true')('It was false'));

const and = p => q => p(q)(p);
console.log("And");
console.log(and(True)(True).toJsBool());
console.log(and(False)(True).toJsBool());
console.log(and(True)(False).toJsBool());
console.log(and(False)(False).toJsBool());

const equals = p => q => p(q)(not(q));
console.log("Equals");
console.log(equals(True)(True).toJsBool());
console.log(equals(False)(True).toJsBool());
console.log(equals(True)(False).toJsBool());
console.log(equals(False)(False).toJsBool());

export { True, False, not, or, ifThenElse, and, equals };
